/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmListaMarcas.java
 *
 * Created on 18/11/2011, 01:17:11 AM
 */

package Marcas;

import Beans.MarcaBean;
import Blogic.MarcaBLogic;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author orellana
 */
public class frmListaMarcas extends javax.swing.JFrame {
    // Atributos de la clase
    private String col[]={"Codigo", "Nombre","Categoria", "IDMarca"};
    public DefaultTableModel modelMarcas=new DefaultTableModel(col,0);
    private String marcaSel="";
    frmAltaMarcas altaMarca=null;

    /** Creates new form frmListaMarcas */
    public frmListaMarcas() {
        initComponents();
        // Definimos posicion del formulario
        this.setLocationRelativeTo(null);
        // Definimos el cerrado de la ventana
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);

        // Definimos el tamaño de las columnas (Tablas)
        getTablaListadoMarcas();
        // Obtenemos Marcas
        obtMarcas();
    }

    // Obtiene marcas registradas
    public void obtMarcas(){
        // Variables locales
        Vector datosMarcas=new Vector();
        MarcaBean sqlBean=new MarcaBean();
        int count = modelMarcas.getRowCount();
        for(int r=0; r<count; r++){
            modelMarcas.removeRow(0);

        }
        // Realizamos la consulta
        datosMarcas=(new MarcaBLogic().getDatosMarcas(sqlBean));
        // Validamos registros encontrados
        if(!datosMarcas.isEmpty()){
            // Vaciamos los datos en la tabla
            // Ciclo for
            for(int i=0; i<datosMarcas.size(); i++){
            MarcaBean detalleDatosMarca=new MarcaBean();
            detalleDatosMarca=(MarcaBean) datosMarcas.elementAt(i);
            // Vaciamos los datos
            modelMarcas.addRow(new Object[]{detalleDatosMarca.getCodigoMarca(), detalleDatosMarca.getNombreMarca(),detalleDatosMarca.getDesCategoria(), detalleDatosMarca.getIdMarca()});
           
            }
        }else{
        modelMarcas.addRow(new Object[]{"No existe Marcas registradas"});

        }
    }

    //Limpiamos el modelo de la tabla
    private void deleteRowModelTable(){
      while(modelMarcas.getRowCount()>0){
            modelMarcas.removeRow(0);
        }
    }

    // Obtiene tamaño columnas tablas
    public void getTablaListadoMarcas(){
        // Vaciamos el modelo con los datos
        tblListaMarcas.setModel(modelMarcas);
        // Definimos el tamaño de las columnas
        // Codigo de la marca
        tblListaMarcas.getColumnModel().getColumn(0).setPreferredWidth(210);
        // Nombre de la marca
        tblListaMarcas.getColumnModel().getColumn(1).setPreferredWidth(210);
        // Categoria
        tblListaMarcas.getColumnModel().getColumn(2).setPreferredWidth(210);
        // id Marca
        tblListaMarcas.getColumnModel().getColumn(3).setMinWidth(0);
        tblListaMarcas.getColumnModel().getColumn(3).setMaxWidth(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        btnNuevaMarca = new javax.swing.JButton();
        btnModificarMarca = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtNombreMarca = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblListaMarcas = new javax.swing.JTable();

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane2.setViewportView(jTable2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemapegasso.SistemaPegassoApp.class).getContext().getResourceMap(frmListaMarcas.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        btnNuevaMarca.setFont(resourceMap.getFont("btnNuevaMarca.font")); // NOI18N
        btnNuevaMarca.setIcon(resourceMap.getIcon("btnNuevaMarca.icon")); // NOI18N
        btnNuevaMarca.setText(resourceMap.getString("btnNuevaMarca.text")); // NOI18N
        btnNuevaMarca.setToolTipText(resourceMap.getString("btnNuevaMarca.toolTipText")); // NOI18N
        btnNuevaMarca.setFocusable(false);
        btnNuevaMarca.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevaMarca.setName("btnNuevaMarca"); // NOI18N
        btnNuevaMarca.setPreferredSize(new java.awt.Dimension(36, 36));
        btnNuevaMarca.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevaMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevaMarcaActionPerformed(evt);
            }
        });
        jToolBar1.add(btnNuevaMarca);

        btnModificarMarca.setFont(resourceMap.getFont("btnModificarMarca.font")); // NOI18N
        btnModificarMarca.setIcon(resourceMap.getIcon("btnModificarMarca.icon")); // NOI18N
        btnModificarMarca.setText(resourceMap.getString("btnModificarMarca.text")); // NOI18N
        btnModificarMarca.setToolTipText(resourceMap.getString("btnModificarMarca.toolTipText")); // NOI18N
        btnModificarMarca.setFocusable(false);
        btnModificarMarca.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnModificarMarca.setName("btnModificarMarca"); // NOI18N
        btnModificarMarca.setPreferredSize(new java.awt.Dimension(28, 34));
        btnModificarMarca.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnModificarMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarMarcaActionPerformed(evt);
            }
        });
        jToolBar1.add(btnModificarMarca);

        btnEliminar.setIcon(resourceMap.getIcon("btnEliminar.icon")); // NOI18N
        btnEliminar.setText(resourceMap.getString("btnEliminar.text")); // NOI18N
        btnEliminar.setToolTipText(resourceMap.getString("btnEliminar.toolTipText")); // NOI18N
        btnEliminar.setActionCommand(resourceMap.getString("btnEliminar.actionCommand")); // NOI18N
        btnEliminar.setFocusable(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEliminar.setName("btnEliminar"); // NOI18N
        btnEliminar.setPreferredSize(new java.awt.Dimension(28, 34));
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEliminar);

        btnBuscar.setFont(resourceMap.getFont("btnBuscar.font")); // NOI18N
        btnBuscar.setIcon(resourceMap.getIcon("btnBuscar.icon")); // NOI18N
        btnBuscar.setText(resourceMap.getString("btnBuscar.text")); // NOI18N
        btnBuscar.setToolTipText(resourceMap.getString("btnBuscar.toolTipText")); // NOI18N
        btnBuscar.setName("btnBuscar"); // NOI18N
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnBuscar);

        btnSalir.setFont(resourceMap.getFont("btnSalir.font")); // NOI18N
        btnSalir.setIcon(resourceMap.getIcon("btnSalir.icon")); // NOI18N
        btnSalir.setText(resourceMap.getString("btnSalir.text")); // NOI18N
        btnSalir.setToolTipText(resourceMap.getString("btnSalir.toolTipText")); // NOI18N
        btnSalir.setFocusable(false);
        btnSalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalir.setName("btnSalir"); // NOI18N
        btnSalir.setPreferredSize(new java.awt.Dimension(28, 34));
        btnSalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        jToolBar1.add(btnSalir);

        jTabbedPane1.setBackground(resourceMap.getColor("jTabbedPane1.background")); // NOI18N
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
        jTabbedPane1.setOpaque(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setBackground(resourceMap.getColor("jLabel1.background")); // NOI18N
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setOpaque(true);

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        txtNombreMarca.setFont(resourceMap.getFont("txtNombreMarca.font")); // NOI18N
        txtNombreMarca.setName("txtNombreMarca"); // NOI18N
        txtNombreMarca.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombreMarcaKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNombreMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNombreMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jLabel4.setBackground(resourceMap.getColor("jLabel4.background")); // NOI18N
        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setForeground(resourceMap.getColor("jLabel4.foreground")); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        jLabel4.setOpaque(true);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        tblListaMarcas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Codigo Marca", "Nombre de Marca"
            }
        ));
        tblListaMarcas.setGridColor(resourceMap.getColor("tblListaMarcas.gridColor")); // NOI18N
        tblListaMarcas.setName("tblListaMarcas"); // NOI18N
        tblListaMarcas.setSelectionBackground(resourceMap.getColor("tblListaMarcas.selectionBackground")); // NOI18N
        tblListaMarcas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblListaMarcasMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblListaMarcas);
        tblListaMarcas.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tblListaMarcas.columnModel.title0")); // NOI18N
        tblListaMarcas.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tblListaMarcas.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 672, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevaMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevaMarcaActionPerformed
        // TODO add your handling code here:
        // Cargamos el formulario alta de marcas
        altaMarca=new frmAltaMarcas(1);
        // Se cacha el boton presionado
        altaMarca.btnGuardar.setActionCommand("nuevaAlta");
        // Se escucha la accion del boton
        altaMarca.btnGuardar.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(e.getActionCommand().equals("nuevaAlta")){
                
                altaMarca.altaClick();
                obtMarcas();
                }

                

            }
        });

        // Mostramos el formulario
          //altaMarca.addWindowFocusListener(true);
        altaMarca.setVisible(true);
      
    }//GEN-LAST:event_btnNuevaMarcaActionPerformed

    private void btnModificarMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarMarcaActionPerformed
        // TODO add your handling code here:
        // Evaluamos si selecciono alguna marca a modificar
        if(!marcaSel.equalsIgnoreCase("")){
        //Cargamos el formulario modificar marcas
        final frmAltaMarcas modificarMarca=new frmAltaMarcas(2);
        //Mostramos el formulario
        modificarMarca.setVisible(true);
        // Cambiamos titulo de la ventana
        modificarMarca.setTitle("Modificar Marca...");

        // Seteamos los Datos
        modificarMarca.setIdMarca(modelMarcas.getValueAt(Integer.parseInt(marcaSel.toString()),3).toString());
        //System.out.println("imprime"+ modelCategorias.getValueAt(Integer.parseInt(categoriaSel.toString()),2).toString());
        // Obtenemos los Datos dela marca
        modificarMarca.obtDatosMarca();

        // Cambiamos el Valor del registro Seleccionado
        marcaSel="";
        //Mostramos la ventana modificar marca
        modificarMarca.setVisible(true);

        modificarMarca.btnGuardar.setActionCommand("nuevaAlta");
        modificarMarca.btnGuardar.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
               if (e.getActionCommand().equals("nuevaAlta")){
               modificarMarca.altaClick();
               obtMarcas();
               }
            }
        });
        }else{
            // Mensaje al usuario
            JOptionPane.showMessageDialog(null,"Debe Seleccionar una Marca a Modificar, Verifique...","Categorias",JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btnModificarMarcaActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        // Cerramos el formulario
        this.setVisible(false);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void tblListaMarcasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblListaMarcasMouseClicked
        // TODO add your handling code here:
        this.marcaSel=Integer.toString(tblListaMarcas.getSelectedRow());
    }//GEN-LAST:event_tblListaMarcasMouseClicked

    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
        // TODO add your handling code here:
    //    modelMarcas.fireTableDataChanged();
    }//GEN-LAST:event_formFocusGained

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
          //Asignamos variables locales
        MarcaBean sqlMarcaBean=new MarcaBean();
        Vector eliminarMarca=new Vector();
        //Eliminamos la marca seleccionada
        //Verificamos que se haya seleccionado un registro de la tabla
        if(!marcaSel.equalsIgnoreCase("")){
             //Seteamos los datos
            sqlMarcaBean.setIdMarca(modelMarcas.getValueAt(Integer.parseInt(marcaSel.toString()), 3).toString());
            //Eliminamos marca
            eliminarMarca=(new MarcaBLogic()).deleteDatosMarca(sqlMarcaBean);
            //Evaluamos respuesta
            if(eliminarMarca.elementAt(0).toString().equalsIgnoreCase("OK")){
            marcaSel="";
            // Mensaje al Usuario
                JOptionPane.showMessageDialog(null,"Marca Eliminado Satisfactoriamente","Eliminar",JOptionPane.INFORMATION_MESSAGE);
                obtMarcas();
                //System.out.println("entro aka de eliminacion");
            }else{
                // Mensaje al Usuario
                JOptionPane.showMessageDialog(null,"Ocurrio un Error al Momento de Eliminar Marcas","Eliminar",JOptionPane.ERROR_MESSAGE);
            }
        }else{
            // Mensaje al Usuario
            JOptionPane.showMessageDialog(null,"Debe Seleccionar un Registro a Eliminar, Verifique","Eliminar",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
           // Variables locales
        MarcaBean sqlBean=new MarcaBean();
        Vector datosMarcaActivo= new Vector();
        MarcaBean marcaActivo= new MarcaBean();
//System.out.println("Entre akiiii buscar");
        //Realizamos la busqueda de la categoria
        //Seteamos los datos
        sqlBean.setNombreMarca(txtNombreMarca.getText());
        datosMarcaActivo=(new MarcaBLogic().buscarDatosMarcaActivo(sqlBean));
        //Limpiamos la tabla
        deleteRowModelTable();
        //Evaluamos resultado obtenido
        if(datosMarcaActivo.size()!=0){
        //Agregamos los datos al modelo
            for(int i=0; i<datosMarcaActivo.size();i++){
                //Vaciamos los datos
                //CategoriaBean categoriaActivos = new CategoriaBean();
            marcaActivo=(MarcaBean) datosMarcaActivo.elementAt(i);
            //Agregamos los datos al modelo de la tabla
            modelMarcas.addRow(new Object[]{marcaActivo.getCodigoMarca(),marcaActivo.getNombreMarca(),marcaActivo.getIdMarca()});
        //System.out.println("imprime categorias "+modelCategorias);
            }
        }else{
        //No existen registros
            //modelCategorias.addRow(new Object[]{"No existen categorias registradas"});

        }
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void txtNombreMarcaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreMarcaKeyPressed
        // TODO add your handling code here:
         //System.out.println("entre akii");
        MarcaBean buscarMarca = new MarcaBean();
        Vector marcaVector = new Vector();
        MarcaBLogic marcaBlogic= new MarcaBLogic();
        buscarMarca.setNombreMarca(txtNombreMarca.getText().toString().trim());

        marcaVector=marcaBlogic.buscarDatosMarcaActivo(buscarMarca);
        if(marcaVector.size()>0){
           deleteRowModelTable();
           for(int i=0; i<marcaVector.size();i++){
               buscarMarca=(MarcaBean) marcaVector.elementAt(i);
           modelMarcas.addRow(new Object[]{buscarMarca.getCodigoMarca(), buscarMarca.getNombreMarca(),buscarMarca.getIdMarca()});
        }
        }
    }//GEN-LAST:event_txtNombreMarcaKeyPressed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmListaMarcas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificarMarca;
    private javax.swing.JButton btnNuevaMarca;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable tblListaMarcas;
    private javax.swing.JTextField txtNombreMarca;
    // End of variables declaration//GEN-END:variables

}
